import { GET, POST, PUT, DELETE } from './request'
import { qs } from '@/utils/param'
import { ProjectBasicInfoType } from '@/modules/project'
import { pagingParams } from './index'
import { GetFilesType, PostMemberType, PutMemberType, PutMembersType, DelMembersType } from './project.d'
import { getFilename } from '@/utils/file'

/**
 * 获取项目详细信息
 * @param  projectId 项目id
 */
export const getCompProject = (projectId:number) => GET(`/project/${ projectId }`)

/**
 * 创建竞赛项目
 */
export const postCompProject = (data:ProjectBasicInfoType) => POST('/project', data)

/**
 * 更新项目详细信息
 */
export const putCompProject = (projectId:number, data:any) => PUT(`/project/${ projectId }`, data)

/**
 * 获取比赛项目所有资源信息
 */
export const getCompResources = ({ id, edit }:GetFilesType) => GET(`/project/${ id }/resources?edit=${ edit }`)

/**
 * 创建项目成员
 */
export const postMember = ({ projectId, member }:PostMemberType) => POST(`/project/member/${ projectId }`, member)

/**
 * 更新项目单个成员信息
 */
export const putMember = ({ projectId, member }:PutMemberType) => PUT(`/project/member/${ projectId }/${ member.memberUserId }`, member)

/**
 * 批量更新项目成员
 */
export const putMembers = ({ projectId, members }:PutMembersType) => PUT(`/project/members/${ projectId }`, members)

/**
  * 删除成员
  */
export const deleteMember = ({ projectId, userId }:DelMembersType) => DELETE(`/project/member/${ projectId }/${ userId }`)

/**
 * 根据id获取课设
 * @param courseDesignId 课设id
 */
export const getCourseDesign = (courseDesignId:number) => GET(`/courseDesign/${ courseDesignId }`)

/**
 * 创建课设项目
 */
export const postCourseDesign = (data:any) => POST(`/courseDesign`, data)

/**
 * 更新课设项目
 */
export const putCourseDesign = (courseDesignId:number, data:any) => PUT(`/courseDesign/${ courseDesignId }`, data)

/**
 * 获取课设项目的附件
 */
export const getCourseResources = ({ id, edit = true }:GetFilesType) => GET(`/courseDesign/${ id }/resources?edit=${ edit }`)

/**
 * 删除资源
 */
export const deleteResource = (resourceId:number) => DELETE(`/project/resource/${ resourceId }`)

/**
 * 修改资源信息
 */
export const putResource = (resourceId:number, data:any) => PUT(`/project/resource/${ resourceId }`, data)

/**
 * 根据获奖等级和文件分类获取参考价格
 */
export const getFilePrice = ({ awardLevel, classifyId }:{awardLevel:number, classifyId:number}) => GET(`/project/resource/purchased/getPrice/${ awardLevel }/${ classifyId }`)

/**
 * 获取上传文件签名
 */
export const getFilesSignature = (projectId:number, filename:string) => GET(`/project/${ projectId }/resources/sign/upload/private?filename=${ getFilename(filename) }`)
/**
 * 获取课设项目上传签名
 */
export const getCourseFileSign = (courseDesignId:number, filename:string) => GET(`/courseDesign/${ courseDesignId }/resources/sign/upload/private?filename=${ getFilename(filename) }`)

/**
 * 创建一条项目附件信息
 */
export const postResource = (projectId:number, data:any) => POST(`/project/resource/${ projectId }`, data)

/**
 * 获取个人项目列表
 */
export const getMyCompProjects = (params:pagingParams) => GET('/project/me', params)
